import java.util.*;
class Solution {
        public boolean canPartition(int[] nums) {
            int len=nums.length;
            if(len==0) {
                return false;
            }
            int sum=0;
            for(int i=0;i<len;i++){
                sum=sum+nums[i];
            }
            int target=sum/2;
            Arrays.sort(nums);
            if(nums[0]>target){
                return false;
            }
            int left=0;
            int right=len-1;
            int leftsum=nums[left];
            int rightsum=nums[right];
            while(left<right){
                if(leftsum<rightsum){
                    left++;
                    leftsum=leftsum+nums[left];
                }else if(leftsum>rightsum){
                    right--;
                    rightsum=rightsum+nums[right];
                }else{
                    if(leftsum==target){
                        return true;
                    }
                    leftsum=leftsum+nums[left];
                    rightsum=rightsum+nums[right];
                }
            }
            return leftsum==rightsum;
        }
    public int maxProduct(int[] nums) {
        int max = Integer.MIN_VALUE, imax = 1, imin = 1;
        for(int i=0; i<nums.length; i++){
            if(nums[i] < 0){
                int tmp = imax;
                imax = imin;
                imin = tmp;
            }
            imax = Math.max(imax*nums[i], nums[i]);
            imin = Math.min(imin*nums[i], nums[i]);

            max = Math.max(max, imax);
        }
        return max;
    }
}
